package vcp.controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import db.parking.beans.Employee;

import vcp.common.AbstractController;
import vcp.common.IController;
import vcp.gui.forms.LoginForm;
import vcp.models.LoginModel;

import vcp.views.LoginView;
import vcp.views.OrderGuestView;

/**
 * Login controller
 * @author G15
 *
 */
public class LoginController extends AbstractController implements
	ActionListener, IController {
	LoginView view;
	LoginModel model;

	@Override
	public void addModel(Object model) {
		this.model = (LoginModel) model;
	}

	@Override
	public void addView(Object view) {
		this.view = (LoginView) view;
	}

	@Override
	public void actionPerformed(ActionEvent eve) {		
		if (eve.getActionCommand().equals("login")) {
			LoginForm form = view.getLoginForm();
			if (!form.getTextUsername().getText().isEmpty()
					|| !form.getTxtPassword().getText().isEmpty()) {
				
				Employee bean = new Employee();
				bean.setUsername(form.getTextUsername().getText());
				bean.setPassword(form.getTxtPassword().getText());
				//System.out.println(bean.getUsername());
				//System.out.println(bean.getPassword());

				model.doLogin(bean);
			}
		}
	}

}
